/*
 * Author: kymars
 * Gitee: https://gitee.com/kymars
 *
 */

#include "includes.h" 
#include "malloc.h"
#include "lan8720.h"
#include "usart.h"
#include "lwip_comm.h" 

#define START_TASK_PRIO					10
#define START_STK_SIZE					64
__align(8) static OS_STK START_TASK_STK[START_STK_SIZE];
void start_task(void *pdata);

#define MAIN_TASK_PRIO       			9
#define MAIN_STK_SIZE  					1024
__align(8) static OS_STK MAIN_TASK_STK[MAIN_STK_SIZE];
void main_task(void *pdata);

int main(void)
{
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
	delay_init(168);

	delay_ms(1000);

	LED_Init();

	PFout(9) = 1;

	FSMC_SRAM_Init();

	my_mem_init(SRAMEX);

	uart_init(115200);

	OSInit();
	OSTaskCreate(start_task, (void *)0, (OS_STK *)&START_TASK_STK[START_STK_SIZE-1], START_TASK_PRIO);
	OSStart();
}

void start_task(void *pdata)
{
	OS_CPU_SR cpu_sr = 0;
	pdata = pdata;
	OSStatInit();
	OS_ENTER_CRITICAL();
	OSTaskCreate(main_task, (void *)0, (OS_STK*)&MAIN_TASK_STK[MAIN_STK_SIZE-1], MAIN_TASK_PRIO);
	OSTaskSuspend(START_TASK_PRIO);
	OS_EXIT_CRITICAL();
} 

void main_task(void *pdata)
{
	int ret = -1;

	ret = lwip_comm_init();
	if (0 != ret)
	{
		printf("lwip_comm_init error!ret = %d.\r\n", ret);
		return ;
	}

	while (1)
	{
		delay_ms(1000);
	}
}


